-- Crimes: (number of stars) (amount of money) (amounts for next star)
-- + Attacking people (1) (0) (10)
-- + Killing people (2) (250) (10)
-- - Stealing a car (1) (0) (5)
-- - Stealing a police car (2) (0) (5)
-- - Pickpocketing (1) (250) (5)

function criminalSpawn ()
	local playerAccount = getPlayerAccount (source)
	if (playerAccount) then
		local currentAttacks = getAccountData (playerAccount, "rpg.spawnattacks")
		if (currentAttacks ~= 0) then
			setAccountData (playerAccount, "rpg.spawnattacks", 0)
		end
		local currentKills = getAccountData (playerAccount, "rpg.spawnkills")
		if (currentKills ~= 0) then
			setAccountData (playerAccount, "rpg.spawnkills", 0)
		end
	end
end

function attackPlayer (attacker, weapon, bodypart, loss)
	if (attacker) then
		if getElementType (attacker) == "player" then
			local attackerAccount = getPlayerAccount (attacker)
			if (attackerAccount) then
				local currentAttacks = getAccountData (attackerAccount, "rpg.spawnattacks")
				local newAttacks = (currentAttacks + 1)
				setAccountData (attackerAccount, "rpg.spawnattacks", newAttacks)
				outputChatBox ("Attacks: "..newAttacks, attacker)
			end
			local currentWantedLevel = getPlayerWantedLevel (attacker)
			if (currentWantedLevel < 6) and (attackerAccount)  then
				local currentAttacks = getAccountData (attackerAccount, "rpg.spawnattacks")
				if (currentAttacks == 10) then
					local newWantedLevel = (currentWantedLevel + 1)
					setPlayerWantedLevel (attacker, newWantedLevel)
					setAccountData (attackerAccount, "rpg.spawnattacks", 0)
				end
			end
		end
	end
end

function killedPlayer (ammo, attacker, weapon, bodypart)
	if (attacker) then
		if getElementType (attacker) == "player" then
			local attackerAccount = getPlayerAccount (attacker)
			if (attackerAccount) then
				local currentKills = getAccountData (attackerAccount, "rpg.spawnkills")
				local newKills = (currentKills + 1)
				setAccountData (attackerAccount, "rpg.spawnkills", newKills)
				outputChatBox ("Kills: "..newKills, attacker)
			end
			givePlayerMoney (attacker, 250)
			local currentWantedLevel = getPlayerWantedLevel (attacker)
			if (currentWantedLevel < 5) then
				local newWantedLevel = (currentWantedLevel + 2)
				setPlayerWantedLevel (attacker, newWantedLevel)
			elseif (currentWantedLevel < 6) then
				local newWantedLevel = (currentWantedLevel + 1)
				setPlayerWantedLevel (attacker, newWantedLevel)
			end
		end
	end
end

addEventHandler ("onPlayerDamage", getRootElement (), attackPlayer)
addEventHandler ("onPlayerWasted", getRootElement (), killedPlayer)
addEventHandler ("onPlayerSpawn", getRootElement (), criminalSpawn)